-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
56e5e4e
commit 43ef982
Showing
48 changed files
with
1,375 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
common/src/main/java/org/anvilpowered/ontime/common/command/CommonOnTimeAddCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* OnTime - AnvilPowered | ||
* Copyright (C) 2020 | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.anvilpowered.ontime.common.command; | ||
|
||
public class CommonOnTimeAddCommand<TUser, TPlayer, TSubject, TString, TCommandSource> | ||
extends CommonOnTimeTwoArgCommand<TUser, TPlayer, TSubject, TString, TCommandSource> { | ||
|
||
public void sendAdd(TCommandSource source, String[] context) { | ||
send(source, context, "add", memberManager::addBonusTime); | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
common/src/main/java/org/anvilpowered/ontime/common/command/CommonOnTimeCheckCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* OnTime - AnvilPowered | ||
* Copyright (C) 2020 | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.anvilpowered.ontime.common.command; | ||
|
||
import com.google.inject.Inject; | ||
import org.anvilpowered.anvil.api.data.registry.Registry; | ||
import org.anvilpowered.anvil.api.plugin.PluginInfo; | ||
import org.anvilpowered.anvil.api.util.PermissionService; | ||
import org.anvilpowered.anvil.api.util.TextService; | ||
import org.anvilpowered.anvil.api.util.UserService; | ||
import org.anvilpowered.ontime.api.data.key.OnTimeKeys; | ||
import org.anvilpowered.ontime.api.member.MemberManager; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
@SuppressWarnings("unchecked") | ||
public class CommonOnTimeCheckCommand<TUser, TPlayer, TSubject, TString, TCommandSource> { | ||
|
||
@Inject | ||
protected MemberManager<TString> memberManager; | ||
|
||
@Inject | ||
private PermissionService<TSubject> permissionService; | ||
|
||
@Inject | ||
private PluginInfo<TString> pluginInfo; | ||
|
||
@Inject | ||
protected Registry registry; | ||
|
||
@Inject | ||
private TextService<TString, TCommandSource> textService; | ||
|
||
@Inject | ||
private UserService<TUser, TPlayer> userService; | ||
|
||
public void sendError(TCommandSource source) { | ||
textService.builder() | ||
.append(pluginInfo.getPrefix()) | ||
.red().append("Specify user or run as player!") | ||
.sendTo(source); | ||
} | ||
|
||
public void sendCheck(TCommandSource source, String[] context, | ||
Class<TPlayer> playerClass, Class<?> consoleClass) { | ||
final boolean isConsole = consoleClass.isAssignableFrom(source.getClass()); | ||
final boolean isPlayer = playerClass.isAssignableFrom(source.getClass()); | ||
if (!isConsole && !(isPlayer && permissionService.hasPermission((TSubject) source, | ||
registry.getOrDefault(OnTimeKeys.CHECK_PERMISSION)))) { | ||
textService.builder() | ||
.append(pluginInfo.getPrefix()) | ||
.red().append("You do not have permission for this command!") | ||
.sendTo(source); | ||
return; | ||
} | ||
final boolean hasExtended = isConsole || permissionService.hasPermission((TSubject) source, | ||
registry.getOrDefault(OnTimeKeys.CHECK_EXTENDED_PERMISSION)); | ||
|
||
CompletableFuture<Optional<UUID>> futureUUID; | ||
if (context.length == 1 && hasExtended) { | ||
futureUUID = userService.getUUID(context[0]); | ||
} else { | ||
futureUUID = CompletableFuture.completedFuture(Optional.empty()); | ||
} | ||
futureUUID.thenAcceptAsync(optionalUserUUID -> { | ||
if (optionalUserUUID.isPresent()) { | ||
memberManager.infoExtended(optionalUserUUID.get()) | ||
.thenAcceptAsync(result -> textService.send(result, source)); | ||
} else if (isPlayer) { | ||
UUID userUUID = userService.getUUID((TUser) source); | ||
if (hasExtended) { | ||
memberManager.infoExtended(userUUID) | ||
.thenAcceptAsync(result -> textService.send(result, source)); | ||
} else { | ||
memberManager.info(userUUID) | ||
.thenAcceptAsync(result -> textService.send(result, source)); | ||
} | ||
} else { | ||
sendError(source); | ||
} | ||
}); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
common/src/main/java/org/anvilpowered/ontime/common/command/CommonOnTimeSetBonusCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* OnTime - AnvilPowered | ||
* Copyright (C) 2020 | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.anvilpowered.ontime.common.command; | ||
|
||
public class CommonOnTimeSetBonusCommand<TUser, TPlayer, TSubject, TString, TCommandSource> | ||
extends CommonOnTimeTwoArgCommand<TUser, TPlayer, TSubject, TString, TCommandSource> { | ||
|
||
public void sendSetBonus(TCommandSource source, String[] context) { | ||
send(source, context, "setbonus", memberManager::setBonusTime); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
common/src/main/java/org/anvilpowered/ontime/common/command/CommonOnTimeSetTotalCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* OnTime - AnvilPowered | ||
* Copyright (C) 2020 | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.anvilpowered.ontime.common.command; | ||
|
||
public class CommonOnTimeSetTotalCommand<TUser, TPlayer, TSubject, TString, TCommandSource> | ||
extends CommonOnTimeTwoArgCommand<TUser, TPlayer, TSubject, TString, TCommandSource> { | ||
|
||
public void sendSetTotal(TCommandSource source, String[] context) { | ||
send(source, context, "set", memberManager::setTotalTime); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
common/src/main/java/org/anvilpowered/ontime/common/command/CommonOnTimeTwoArgCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* OnTime - AnvilPowered | ||
* Copyright (C) 2020 | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.anvilpowered.ontime.common.command; | ||
|
||
import com.google.inject.Inject; | ||
import org.anvilpowered.anvil.api.data.registry.Registry; | ||
import org.anvilpowered.anvil.api.plugin.PluginInfo; | ||
import org.anvilpowered.anvil.api.util.PermissionService; | ||
import org.anvilpowered.anvil.api.util.TextService; | ||
import org.anvilpowered.anvil.api.util.UserService; | ||
import org.anvilpowered.ontime.api.data.key.OnTimeKeys; | ||
import org.anvilpowered.ontime.api.member.MemberManager; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.function.BiFunction; | ||
|
||
public class CommonOnTimeTwoArgCommand<TUser, TPlayer, TSubject, TString, TCommandSource> { | ||
|
||
@Inject | ||
protected MemberManager<TString> memberManager; | ||
|
||
@Inject | ||
protected PermissionService<TSubject> permissionService; | ||
|
||
@Inject | ||
private PluginInfo<TString> pluginInfo; | ||
|
||
@Inject | ||
protected Registry registry; | ||
|
||
@Inject | ||
private TextService<TString, TCommandSource> textService; | ||
|
||
@Inject | ||
private UserService<TUser, TPlayer> userService; | ||
|
||
public void send(TCommandSource source, String[] context, String command, | ||
BiFunction<UUID, String, CompletableFuture<TString>> function) { | ||
if (!permissionService.hasPermission((TSubject) source, | ||
registry.getOrDefault(OnTimeKeys.EDIT_PERMISSION))) { | ||
textService.builder() | ||
.append(pluginInfo.getPrefix()) | ||
.red().append("You do not have permission for this command!") | ||
.sendTo(source); | ||
return; | ||
} | ||
if (context.length != 2) { | ||
textService.builder() | ||
.append(pluginInfo.getPrefix()) | ||
.red().append("Not enough arguments!") | ||
.append("\n", command, " ").appendJoining(" ", context) | ||
.append("\n^\nUsage: /ontime ", command, " <user> <time...>") | ||
.sendTo(source); | ||
return; | ||
} | ||
userService.getUUID(context[0]).thenAcceptAsync(userUUID -> { | ||
if (!userUUID.isPresent()) { | ||
textService.builder() | ||
.append(pluginInfo.getPrefix()) | ||
.red().append("No values matching pattern '", context[0], "' present for user!") | ||
.append("\n", command, " ").appendJoining(" ", context) | ||
.append("\n").appendCount(command.length() + 1, " ") | ||
.append("^\nUsage: /ontime ", command, " <user> <time...>") | ||
.sendTo(source); | ||
return; | ||
} | ||
function.apply(userUUID.get(), context[1]) | ||
.thenAcceptAsync(result -> textService.send(result, source)); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.