Skip to content

Commit

Permalink
Don't require admin member to be set in abstract admin script
Browse files Browse the repository at this point in the history
  • Loading branch information
AntumDeluge committed May 7, 2024
1 parent abce198 commit 106ee5b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
33 changes: 25 additions & 8 deletions src/games/stendhal/server/core/scripting/AbstractAdminScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
***************************************************************************/
package games.stendhal.server.core.scripting;

import static com.google.common.base.Preconditions.checkNotNull;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
Expand All @@ -39,7 +37,7 @@ public abstract class AbstractAdminScript extends ScriptImpl {

@Override
public void execute(final Player admin, final List<String> args) {
this.admin = checkNotNull(admin);
this.admin = admin;
final int minparams = getMinParams();
final int maxparams = getMaxParams();
if (maxparams > -1 && maxparams < minparams) {
Expand All @@ -64,14 +62,33 @@ public void execute(final Player admin, final List<String> args) {
run(args);
}

/**
* Sends a private text to admin if set.
*
* @param _type
* Notification type.
* @param msg
* Message contents.
*/
private void sendTextInternal(final NotificationType _type, final String msg) {
if (admin == null) {
return;
}
if (_type == null) {
admin.sendPrivateText(msg);
} else {
admin.sendPrivateText(_type, msg);
}
}

/**
* Wrapper for sending standard text to admin.
*
* @param msg
* Message contents.
*/
protected void sendText(final String msg) {
admin.sendPrivateText(msg);
sendTextInternal(null, msg);
}

/**
Expand All @@ -81,7 +98,7 @@ protected void sendText(final String msg) {
* Messag contents.
*/
protected void sendInfo(final String msg) {
admin.sendPrivateText(NotificationType.INFORMATION, msg);
sendTextInternal(NotificationType.INFORMATION, msg);
}

/**
Expand All @@ -91,7 +108,7 @@ protected void sendInfo(final String msg) {
* Message contents.
*/
protected void sendWarning(final String msg) {
admin.sendPrivateText(NotificationType.WARNING, msg);
sendTextInternal(NotificationType.WARNING, msg);
}

/**
Expand All @@ -101,7 +118,7 @@ protected void sendWarning(final String msg) {
* Message contents.
*/
protected void sendError(final String msg) {
admin.sendPrivateText(NotificationType.ERROR, msg);
sendTextInternal(NotificationType.ERROR, msg);
}

/**
Expand Down Expand Up @@ -130,7 +147,7 @@ private boolean hasHelp() {
* Displays usage information to admin.
*/
public void showUsage() {
admin.sendPrivateText(getUsage());
sendTextInternal(null, getUsage());
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/games/stendhal/server/script/DebugWeather.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
***************************************************************************/
package games.stendhal.server.script;

import static com.google.common.base.Preconditions.checkNotNull;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand All @@ -31,6 +33,7 @@ public class DebugWeather extends AbstractAdminScript {

@Override
protected void run(final List<String> args) {
checkNotNull(admin);
final int argc = args.size();
final Set<String> registered = Collections.unmodifiableSet(getTypes());
if (registered.size() == 0) {
Expand Down
3 changes: 3 additions & 0 deletions src/games/stendhal/server/script/ListSpawnPoints.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
***************************************************************************/
package games.stendhal.server.script;

import static com.google.common.base.Preconditions.checkNotNull;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -37,6 +39,7 @@ public class ListSpawnPoints extends AbstractAdminScript {

@Override
protected void run(final List<String> args) {
checkNotNull(admin);
final int argc = args.size();
String zonename = null;
String spawntype = null;
Expand Down
3 changes: 3 additions & 0 deletions src/games/stendhal/server/script/SpawnCreature.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
***************************************************************************/
package games.stendhal.server.script;

import static com.google.common.base.Preconditions.checkNotNull;

import java.util.Arrays;
import java.util.List;

Expand All @@ -29,6 +31,7 @@ public class SpawnCreature extends AbstractAdminScript {

@Override
protected void run(final List<String> args) {
checkNotNull(admin);
int x;
int y;
try {
Expand Down

0 comments on commit 106ee5b

Please sign in to comment.