Update SalesAnnouncement system to allow clans-only announcements and make cross-server updating work properly
This commit is contained in:
parent
f202085eeb
commit
953ad66aca
@ -154,7 +154,7 @@ public class ClansHub extends JavaPlugin
|
|||||||
ConditionManager condition = new ConditionManager(this);
|
ConditionManager condition = new ConditionManager(this);
|
||||||
ThankManager thankManager = new ThankManager(this, clientManager, donationManager);
|
ThankManager thankManager = new ThankManager(this, clientManager, donationManager);
|
||||||
BoosterManager boosterManager = new BoosterManager(this, "", clientManager, donationManager, inventoryManager, thankManager);
|
BoosterManager boosterManager = new BoosterManager(this, "", clientManager, donationManager, inventoryManager, thankManager);
|
||||||
HubManager hubManager = new HubManager(this, blockRestore, clientManager, incognito, donationManager, inventoryManager, condition, disguiseManager, new TaskManager(this, clientManager), portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager, new HologramManager(this, packetHandler), npcManager, packetHandler, punish, serverStatusManager, customDataManager, thankManager, boosterManager);
|
HubManager hubManager = new HubManager(this, blockRestore, clientManager, incognito, donationManager, inventoryManager, condition, disguiseManager, new TaskManager(this, clientManager), portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager, hologramManager, npcManager, packetHandler, punish, serverStatusManager, customDataManager, thankManager, boosterManager, castleManager);
|
||||||
|
|
||||||
ClansTransferManager serverManager = new ClansTransferManager(this, clientManager, donationManager, partyManager, portal, hubManager);
|
ClansTransferManager serverManager = new ClansTransferManager(this, clientManager, donationManager, partyManager, portal, hubManager);
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ public class HubManager extends MiniPlugin implements IChatMessageFormatter
|
|||||||
|
|
||||||
private HashMap<String, ArrayList<String>> _creativeAdmin = new HashMap<String, ArrayList<String>>();
|
private HashMap<String, ArrayList<String>> _creativeAdmin = new HashMap<String, ArrayList<String>>();
|
||||||
|
|
||||||
public HubManager(JavaPlugin plugin, BlockRestore blockRestore, CoreClientManager clientManager, IncognitoManager incognito, DonationManager donationManager, InventoryManager inventoryManager, ConditionManager conditionManager, DisguiseManager disguiseManager, TaskManager taskManager, Portal portal, PartyManager partyManager, PreferencesManager preferences, PetManager petManager, PollManager pollManager, StatsManager statsManager, AchievementManager achievementManager, HologramManager hologramManager, NpcManager npcManager, PacketHandler packetHandler, Punish punish, ServerStatusManager serverStatusManager, CustomDataManager customDataManager, ThankManager thankManager, BoosterManager boosterManager)
|
public HubManager(JavaPlugin plugin, BlockRestore blockRestore, CoreClientManager clientManager, IncognitoManager incognito, DonationManager donationManager, InventoryManager inventoryManager, ConditionManager conditionManager, DisguiseManager disguiseManager, TaskManager taskManager, Portal portal, PartyManager partyManager, PreferencesManager preferences, PetManager petManager, PollManager pollManager, StatsManager statsManager, AchievementManager achievementManager, HologramManager hologramManager, NpcManager npcManager, PacketHandler packetHandler, Punish punish, ServerStatusManager serverStatusManager, CustomDataManager customDataManager, ThankManager thankManager, BoosterManager boosterManager, CastleManager castleManager)
|
||||||
{
|
{
|
||||||
super("Hub Manager", plugin);
|
super("Hub Manager", plugin);
|
||||||
|
|
||||||
@ -195,7 +195,6 @@ public class HubManager extends MiniPlugin implements IChatMessageFormatter
|
|||||||
_inventoryManager = inventoryManager;
|
_inventoryManager = inventoryManager;
|
||||||
new BenefitManager(plugin, clientManager, _inventoryManager);
|
new BenefitManager(plugin, clientManager, _inventoryManager);
|
||||||
|
|
||||||
CastleManager castleManager = new CastleManager(_plugin, _clientManager, hologramManager, false);
|
|
||||||
_gadgetManager = new GadgetManager(_plugin, clientManager, donationManager, _inventoryManager, _mountManager, petManager, preferences, disguiseManager, blockRestore, new ProjectileManager(plugin), achievementManager, packetHandler, hologramManager, incognito, castleManager);
|
_gadgetManager = new GadgetManager(_plugin, clientManager, donationManager, _inventoryManager, _mountManager, petManager, preferences, disguiseManager, blockRestore, new ProjectileManager(plugin), achievementManager, packetHandler, hologramManager, incognito, castleManager);
|
||||||
|
|
||||||
FacebookManager facebookManager = new FacebookManager(plugin, clientManager, donationManager, inventoryManager);
|
FacebookManager facebookManager = new FacebookManager(plugin, clientManager, donationManager, inventoryManager);
|
||||||
|
@ -12,12 +12,12 @@ import mineplex.core.itemstack.ItemBuilder;
|
|||||||
|
|
||||||
public class SalesAnnouncementData
|
public class SalesAnnouncementData
|
||||||
{
|
{
|
||||||
private final int _id;
|
private final Integer _id;
|
||||||
private final Rank[] _displayTo;
|
private final Rank[] _displayTo;
|
||||||
private final String _message;
|
private final String _message;
|
||||||
private boolean _enabled;
|
private boolean _enabled;
|
||||||
|
|
||||||
public SalesAnnouncementData(int id, Rank[] displayTo, String message, boolean enabled)
|
public SalesAnnouncementData(Integer id, Rank[] displayTo, String message, boolean enabled)
|
||||||
{
|
{
|
||||||
_id = id;
|
_id = id;
|
||||||
_displayTo = displayTo;
|
_displayTo = displayTo;
|
||||||
@ -25,7 +25,7 @@ public class SalesAnnouncementData
|
|||||||
_enabled = enabled;
|
_enabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId()
|
public Integer getId()
|
||||||
{
|
{
|
||||||
return _id;
|
return _id;
|
||||||
}
|
}
|
||||||
|
@ -4,16 +4,17 @@ import mineplex.serverdata.commands.ServerCommand;
|
|||||||
|
|
||||||
public class SalesAnnouncementDeleteCommand extends ServerCommand
|
public class SalesAnnouncementDeleteCommand extends ServerCommand
|
||||||
{
|
{
|
||||||
private String _id;
|
private Integer _id;
|
||||||
private String _from;
|
private String _from;
|
||||||
|
private boolean _clans;
|
||||||
|
|
||||||
public SalesAnnouncementDeleteCommand(String id, String from)
|
public SalesAnnouncementDeleteCommand(Integer id, String from, boolean clans)
|
||||||
{
|
{
|
||||||
_id = id;
|
_id = id;
|
||||||
_from = from;
|
_from = from;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId()
|
public Integer getId()
|
||||||
{
|
{
|
||||||
return _id;
|
return _id;
|
||||||
}
|
}
|
||||||
@ -22,4 +23,9 @@ public class SalesAnnouncementDeleteCommand extends ServerCommand
|
|||||||
{
|
{
|
||||||
return _from;
|
return _from;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isClans()
|
||||||
|
{
|
||||||
|
return _clans;
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,9 +1,8 @@
|
|||||||
package mineplex.clanshub.salesannouncements;
|
package mineplex.clanshub.salesannouncements;
|
||||||
|
|
||||||
import mineplex.serverdata.commands.CommandCallback;
|
import mineplex.serverdata.commands.CommandCallback;
|
||||||
import mineplex.serverdata.commands.ServerCommand;
|
|
||||||
|
|
||||||
public class SalesAnnouncementDeleteHandler implements CommandCallback
|
public class SalesAnnouncementDeleteHandler implements CommandCallback<SalesAnnouncementDeleteCommand>
|
||||||
{
|
{
|
||||||
private final SalesAnnouncementManager _manager;
|
private final SalesAnnouncementManager _manager;
|
||||||
|
|
||||||
@ -13,16 +12,16 @@ public class SalesAnnouncementDeleteHandler implements CommandCallback
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(ServerCommand command)
|
public void run(SalesAnnouncementDeleteCommand command)
|
||||||
{
|
{
|
||||||
if (!(command instanceof SalesAnnouncementDeleteCommand))
|
if (_manager.getServer().equalsIgnoreCase(command.getFrom()))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_manager.getServer().equalsIgnoreCase(((SalesAnnouncementDeleteCommand) command).getFrom()))
|
if (_manager.CLANS != command.isClans())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_manager.handleRemoteDeletion(Integer.parseInt(((SalesAnnouncementDeleteCommand)command).getId()));
|
_manager.handleRemoteDeletion(command.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,14 +1,13 @@
|
|||||||
package mineplex.clanshub.salesannouncements;
|
package mineplex.clanshub.salesannouncements;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
|
|
||||||
import mineplex.core.Managers;
|
import mineplex.core.Managers;
|
||||||
import mineplex.core.MiniPlugin;
|
import mineplex.core.MiniPlugin;
|
||||||
import mineplex.core.account.CoreClientManager;
|
import mineplex.core.account.CoreClientManager;
|
||||||
@ -22,22 +21,23 @@ import mineplex.serverdata.commands.ServerCommandManager;
|
|||||||
public class SalesAnnouncementManager extends MiniPlugin
|
public class SalesAnnouncementManager extends MiniPlugin
|
||||||
{
|
{
|
||||||
private static final String LINE = C.cDGreenB + C.Strike + "=============================================";
|
private static final String LINE = C.cDGreenB + C.Strike + "=============================================";
|
||||||
private final List<SalesAnnouncementData> _data = Lists.newArrayList();
|
private final Map<Integer, SalesAnnouncementData> _data = new HashMap<>();
|
||||||
private final SalesAnnouncementRepository _repo;
|
private final SalesAnnouncementRepository _repo;
|
||||||
|
public final boolean CLANS = true;
|
||||||
|
|
||||||
public SalesAnnouncementManager(JavaPlugin plugin)
|
public SalesAnnouncementManager(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super("Sales", plugin);
|
super("Sales", plugin);
|
||||||
_repo = new SalesAnnouncementRepository(plugin);
|
_repo = new SalesAnnouncementRepository(plugin, CLANS);
|
||||||
_repo.loadAnnouncements(_data);
|
_repo.loadAnnouncements(_data);
|
||||||
|
|
||||||
addCommand(new SalesAnnouncementCommand(this));
|
addCommand(new SalesAnnouncementCommand(this));
|
||||||
|
|
||||||
ServerCommandManager.getInstance().registerCommandType("SalesAnnouncementUpdate", SalesAnnouncementUpdateCommand.class, new SalesAnnouncementUpdateHandler(this));
|
ServerCommandManager.getInstance().registerCommandType(SalesAnnouncementUpdateCommand.class, new SalesAnnouncementUpdateHandler(this));
|
||||||
ServerCommandManager.getInstance().registerCommandType("SalesAnnouncementDelete", SalesAnnouncementDeleteCommand.class, new SalesAnnouncementDeleteHandler(this));
|
ServerCommandManager.getInstance().registerCommandType(SalesAnnouncementDeleteCommand.class, new SalesAnnouncementDeleteHandler(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SalesAnnouncementData> getLoadedAnnouncements()
|
public Map<Integer, SalesAnnouncementData> getLoadedAnnouncements()
|
||||||
{
|
{
|
||||||
return _data;
|
return _data;
|
||||||
}
|
}
|
||||||
@ -57,8 +57,8 @@ public class SalesAnnouncementManager extends MiniPlugin
|
|||||||
_repo.createAnnouncement(displayTo, message, data ->
|
_repo.createAnnouncement(displayTo, message, data ->
|
||||||
{
|
{
|
||||||
UtilPlayer.message(creator, F.main(getName(), "Announcement successfully created!"));
|
UtilPlayer.message(creator, F.main(getName(), "Announcement successfully created!"));
|
||||||
_data.add(data);
|
_data.put(data.getId(), data);
|
||||||
new SalesAnnouncementUpdateCommand(data.getId() + "", getServer()).publish();
|
new SalesAnnouncementUpdateCommand(data.getId(), getServer(), CLANS).publish();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,9 +73,9 @@ public class SalesAnnouncementManager extends MiniPlugin
|
|||||||
UtilPlayer.message(deletor, F.main(getName(), "Successfully deleted announcement!"));
|
UtilPlayer.message(deletor, F.main(getName(), "Successfully deleted announcement!"));
|
||||||
if (!forceRemoveFromList)
|
if (!forceRemoveFromList)
|
||||||
{
|
{
|
||||||
_data.remove(data);
|
_data.remove(data.getId());
|
||||||
}
|
}
|
||||||
new SalesAnnouncementDeleteCommand(data.getId() + "", getServer()).publish();
|
new SalesAnnouncementDeleteCommand(data.getId(), getServer(), CLANS).publish();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,23 +85,26 @@ public class SalesAnnouncementManager extends MiniPlugin
|
|||||||
_repo.updateAnnouncementStatus(data, () ->
|
_repo.updateAnnouncementStatus(data, () ->
|
||||||
{
|
{
|
||||||
UtilPlayer.message(toggler, F.main(getName(), "Successfully toggled announcement!"));
|
UtilPlayer.message(toggler, F.main(getName(), "Successfully toggled announcement!"));
|
||||||
new SalesAnnouncementUpdateCommand(data.getId() + "", getServer()).publish();
|
new SalesAnnouncementUpdateCommand(data.getId(), getServer(), CLANS).publish();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleRemoteDeletion(int id)
|
public void handleRemoteDeletion(int id)
|
||||||
{
|
{
|
||||||
_data.removeIf(data -> data.getId() == id);
|
runSync(() ->
|
||||||
|
{
|
||||||
|
_data.remove(Integer.valueOf(id));
|
||||||
UtilServer.CallEvent(new SalesAnnouncementRemoteListUpdateEvent());
|
UtilServer.CallEvent(new SalesAnnouncementRemoteListUpdateEvent());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleRemoteUpdate(int id)
|
public void handleRemoteUpdate(int id)
|
||||||
{
|
{
|
||||||
if (_data.stream().filter(data -> data.getId() == id).toArray().length > 0)
|
if (_data.containsKey(Integer.valueOf(id)))
|
||||||
{
|
{
|
||||||
_repo.loadAnnouncement(id, data ->
|
_repo.loadAnnouncement(id, data ->
|
||||||
{
|
{
|
||||||
_data.stream().filter(existing -> existing.getId() == data.getId()).forEach(existing -> existing.setEnabled(data.isEnabled()));
|
_data.get(data.getId()).setEnabled(data.isEnabled());
|
||||||
UtilServer.CallEvent(new SalesAnnouncementRemoteListUpdateEvent());
|
UtilServer.CallEvent(new SalesAnnouncementRemoteListUpdateEvent());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -109,7 +112,7 @@ public class SalesAnnouncementManager extends MiniPlugin
|
|||||||
{
|
{
|
||||||
_repo.loadAnnouncement(id, data ->
|
_repo.loadAnnouncement(id, data ->
|
||||||
{
|
{
|
||||||
_data.add(data);
|
_data.put(data.getId(), data);
|
||||||
UtilServer.CallEvent(new SalesAnnouncementRemoteListUpdateEvent());
|
UtilServer.CallEvent(new SalesAnnouncementRemoteListUpdateEvent());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -118,7 +121,7 @@ public class SalesAnnouncementManager extends MiniPlugin
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onJoin(PlayerJoinEvent event)
|
public void onJoin(PlayerJoinEvent event)
|
||||||
{
|
{
|
||||||
if (_data.isEmpty() || _data.stream().filter(data -> data.isEnabled()).toArray().length == 0)
|
if (_data.isEmpty() || !_data.values().stream().filter(data -> data.isEnabled()).findAny().isPresent())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -127,7 +130,7 @@ public class SalesAnnouncementManager extends MiniPlugin
|
|||||||
|
|
||||||
runSyncLater(() ->
|
runSyncLater(() ->
|
||||||
{
|
{
|
||||||
_data.stream().filter(data -> data.isEnabled() && data.shouldDisplayTo(rank)).forEach(data ->
|
_data.values().stream().filter(data -> data.isEnabled() && data.shouldDisplayTo(rank)).forEach(data ->
|
||||||
{
|
{
|
||||||
player.sendMessage(" ");
|
player.sendMessage(" ");
|
||||||
player.sendMessage(LINE);
|
player.sendMessage(LINE);
|
||||||
|
@ -36,10 +36,11 @@ public class SalesAnnouncementPage implements Listener
|
|||||||
private void setup()
|
private void setup()
|
||||||
{
|
{
|
||||||
_buttons.clear();
|
_buttons.clear();
|
||||||
for (int i = 0; i < _manager.getLoadedAnnouncements().size(); i++)
|
int i = 0;
|
||||||
|
for (SalesAnnouncementData data : _manager.getLoadedAnnouncements().values())
|
||||||
{
|
{
|
||||||
SalesAnnouncementData data = _manager.getLoadedAnnouncements().get(i);
|
|
||||||
_buttons.put(i, new SalesAnnouncementButton(data, this));
|
_buttons.put(i, new SalesAnnouncementButton(data, this));
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
updateButtons(false);
|
updateButtons(false);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package mineplex.clanshub.salesannouncements;
|
package mineplex.clanshub.salesannouncements;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@ -9,7 +11,6 @@ import com.google.common.collect.Lists;
|
|||||||
|
|
||||||
import mineplex.core.common.Rank;
|
import mineplex.core.common.Rank;
|
||||||
import mineplex.core.common.util.Callback;
|
import mineplex.core.common.util.Callback;
|
||||||
import mineplex.core.database.MinecraftRepository;
|
|
||||||
import mineplex.serverdata.database.DBPool;
|
import mineplex.serverdata.database.DBPool;
|
||||||
import mineplex.serverdata.database.RepositoryBase;
|
import mineplex.serverdata.database.RepositoryBase;
|
||||||
import mineplex.serverdata.database.column.ColumnBoolean;
|
import mineplex.serverdata.database.column.ColumnBoolean;
|
||||||
@ -18,20 +19,22 @@ import mineplex.serverdata.database.column.ColumnVarChar;
|
|||||||
|
|
||||||
public class SalesAnnouncementRepository extends RepositoryBase
|
public class SalesAnnouncementRepository extends RepositoryBase
|
||||||
{
|
{
|
||||||
private static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS salesAnnouncements (id INT NOT NULL AUTO_INCREMENT, ranks VARCHAR(250), message VARCHAR(256), enabled BOOL, PRIMARY KEY (id));";
|
private static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS salesAnnouncements (id INT NOT NULL AUTO_INCREMENT, ranks VARCHAR(250), message VARCHAR(256), enabled BOOL, clans BOOL, PRIMARY KEY (id), INDEX typeIndex (clans));";
|
||||||
|
|
||||||
private static final String GET_ANNOUNCEMENTS = "SELECT * FROM salesAnnouncements;";
|
private static final String GET_ANNOUNCEMENTS = "SELECT * FROM salesAnnouncements WHERE clans=?;";
|
||||||
private static final String GET_ANNOUNCEMENT = "SELECT * FROM salesAnnouncements WHERE id=?;";
|
private static final String GET_ANNOUNCEMENT = "SELECT * FROM salesAnnouncements WHERE id=?;";
|
||||||
private static final String UPDATE_ANNOUNCEMENT_STATUS = "UPDATE salesAnnouncements SET enabled=? WHERE id=?;";
|
private static final String UPDATE_ANNOUNCEMENT_STATUS = "UPDATE salesAnnouncements SET enabled=? WHERE id=?;";
|
||||||
private static final String INSERT_ANNOUNCEMENT = "INSERT INTO salesAnnouncements (ranks, message, enabled) VALUES(?, ?, ?);";
|
private static final String INSERT_ANNOUNCEMENT = "INSERT INTO salesAnnouncements (ranks, message, enabled, clans) VALUES(?, ?, ?, ?);";
|
||||||
private static final String DELETE_ANNOUNCEMENT = "DELETE FROM salesAnnouncements WHERE id=?;";
|
private static final String DELETE_ANNOUNCEMENT = "DELETE FROM salesAnnouncements WHERE id=?;";
|
||||||
|
|
||||||
private final JavaPlugin _plugin;
|
private final JavaPlugin _plugin;
|
||||||
|
private final boolean _clans;
|
||||||
|
|
||||||
public SalesAnnouncementRepository(JavaPlugin plugin)
|
public SalesAnnouncementRepository(JavaPlugin plugin, boolean clans)
|
||||||
{
|
{
|
||||||
super(DBPool.getAccount());
|
super(DBPool.getAccount());
|
||||||
_plugin = plugin;
|
_plugin = plugin;
|
||||||
|
_clans = clans;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runAsync(Runnable runnable)
|
private void runAsync(Runnable runnable)
|
||||||
@ -44,13 +47,13 @@ public class SalesAnnouncementRepository extends RepositoryBase
|
|||||||
Bukkit.getScheduler().runTask(_plugin, runnable);
|
Bukkit.getScheduler().runTask(_plugin, runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadAnnouncements(final List<SalesAnnouncementData> announcementList)
|
public void loadAnnouncements(final Map<Integer, SalesAnnouncementData> map)
|
||||||
{
|
{
|
||||||
runAsync(() ->
|
runAsync(() ->
|
||||||
{
|
{
|
||||||
executeQuery(GET_ANNOUNCEMENTS, resultSet ->
|
executeQuery(GET_ANNOUNCEMENTS, resultSet ->
|
||||||
{
|
{
|
||||||
final List<SalesAnnouncementData> data = Lists.newArrayList();
|
final List<SalesAnnouncementData> data = new ArrayList<>();
|
||||||
while (resultSet.next())
|
while (resultSet.next())
|
||||||
{
|
{
|
||||||
int id = resultSet.getInt("id");
|
int id = resultSet.getInt("id");
|
||||||
@ -71,15 +74,15 @@ public class SalesAnnouncementRepository extends RepositoryBase
|
|||||||
String message = resultSet.getString("message");
|
String message = resultSet.getString("message");
|
||||||
boolean enabled = resultSet.getBoolean("enabled");
|
boolean enabled = resultSet.getBoolean("enabled");
|
||||||
|
|
||||||
data.add(new SalesAnnouncementData(id, displayTo, message, enabled));
|
data.add(new SalesAnnouncementData(Integer.valueOf(id), displayTo, message, enabled));
|
||||||
}
|
}
|
||||||
|
|
||||||
runSync(() ->
|
runSync(() ->
|
||||||
{
|
{
|
||||||
announcementList.clear();
|
map.clear();
|
||||||
data.forEach(sData -> announcementList.add(sData));
|
data.forEach(sData -> map.put(sData.getId(), sData));
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}, new ColumnBoolean("clans", _clans));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +112,7 @@ public class SalesAnnouncementRepository extends RepositoryBase
|
|||||||
String message = resultSet.getString("message");
|
String message = resultSet.getString("message");
|
||||||
boolean enabled = resultSet.getBoolean("enabled");
|
boolean enabled = resultSet.getBoolean("enabled");
|
||||||
|
|
||||||
final SalesAnnouncementData data = new SalesAnnouncementData(aId, displayTo, message, enabled);
|
final SalesAnnouncementData data = new SalesAnnouncementData(Integer.valueOf(aId), displayTo, message, enabled);
|
||||||
runSync(() ->
|
runSync(() ->
|
||||||
{
|
{
|
||||||
callback.run(data);
|
callback.run(data);
|
||||||
@ -139,7 +142,7 @@ public class SalesAnnouncementRepository extends RepositoryBase
|
|||||||
runSync(() -> callback.run(data));
|
runSync(() -> callback.run(data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, new ColumnVarChar("ranks", 250, rankStr), new ColumnVarChar("message", 256, message), new ColumnBoolean("enabled", true));
|
}, new ColumnVarChar("ranks", 250, rankStr), new ColumnVarChar("message", 256, message), new ColumnBoolean("enabled", true), new ColumnBoolean("clans", _clans));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +150,7 @@ public class SalesAnnouncementRepository extends RepositoryBase
|
|||||||
{
|
{
|
||||||
runAsync(() ->
|
runAsync(() ->
|
||||||
{
|
{
|
||||||
executeUpdate(UPDATE_ANNOUNCEMENT_STATUS, new ColumnBoolean("enabled", data.isEnabled()), new ColumnInt("id", data.getId()));
|
executeUpdate(UPDATE_ANNOUNCEMENT_STATUS, new ColumnBoolean("enabled", data.isEnabled()), new ColumnInt("id", data.getId().intValue()));
|
||||||
if (after != null)
|
if (after != null)
|
||||||
{
|
{
|
||||||
runSync(after);
|
runSync(after);
|
||||||
@ -159,7 +162,7 @@ public class SalesAnnouncementRepository extends RepositoryBase
|
|||||||
{
|
{
|
||||||
runAsync(() ->
|
runAsync(() ->
|
||||||
{
|
{
|
||||||
executeUpdate(DELETE_ANNOUNCEMENT, new ColumnInt("id", data.getId()));
|
executeUpdate(DELETE_ANNOUNCEMENT, new ColumnInt("id", data.getId().intValue()));
|
||||||
if (after != null)
|
if (after != null)
|
||||||
{
|
{
|
||||||
runSync(after);
|
runSync(after);
|
||||||
|
@ -4,16 +4,18 @@ import mineplex.serverdata.commands.ServerCommand;
|
|||||||
|
|
||||||
public class SalesAnnouncementUpdateCommand extends ServerCommand
|
public class SalesAnnouncementUpdateCommand extends ServerCommand
|
||||||
{
|
{
|
||||||
private String _id;
|
private Integer _id;
|
||||||
private String _from;
|
private String _from;
|
||||||
|
private boolean _clans;
|
||||||
|
|
||||||
public SalesAnnouncementUpdateCommand(String id, String from)
|
public SalesAnnouncementUpdateCommand(Integer id, String from, boolean clans)
|
||||||
{
|
{
|
||||||
_id = id;
|
_id = id;
|
||||||
_from = from;
|
_from = from;
|
||||||
|
_clans = clans;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId()
|
public Integer getId()
|
||||||
{
|
{
|
||||||
return _id;
|
return _id;
|
||||||
}
|
}
|
||||||
@ -22,4 +24,9 @@ public class SalesAnnouncementUpdateCommand extends ServerCommand
|
|||||||
{
|
{
|
||||||
return _from;
|
return _from;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isClans()
|
||||||
|
{
|
||||||
|
return _clans;
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,9 +1,8 @@
|
|||||||
package mineplex.clanshub.salesannouncements;
|
package mineplex.clanshub.salesannouncements;
|
||||||
|
|
||||||
import mineplex.serverdata.commands.CommandCallback;
|
import mineplex.serverdata.commands.CommandCallback;
|
||||||
import mineplex.serverdata.commands.ServerCommand;
|
|
||||||
|
|
||||||
public class SalesAnnouncementUpdateHandler implements CommandCallback
|
public class SalesAnnouncementUpdateHandler implements CommandCallback<SalesAnnouncementUpdateCommand>
|
||||||
{
|
{
|
||||||
private final SalesAnnouncementManager _manager;
|
private final SalesAnnouncementManager _manager;
|
||||||
|
|
||||||
@ -13,16 +12,16 @@ public class SalesAnnouncementUpdateHandler implements CommandCallback
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(ServerCommand command)
|
public void run(SalesAnnouncementUpdateCommand command)
|
||||||
{
|
{
|
||||||
if (!(command instanceof SalesAnnouncementUpdateCommand))
|
if (_manager.getServer().equalsIgnoreCase(command.getFrom()))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_manager.getServer().equalsIgnoreCase(((SalesAnnouncementUpdateCommand) command).getFrom()))
|
if (_manager.CLANS != command.isClans())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_manager.handleRemoteUpdate(Integer.parseInt(((SalesAnnouncementUpdateCommand)command).getId()));
|
_manager.handleRemoteUpdate(command.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -12,12 +12,12 @@ import mineplex.core.itemstack.ItemBuilder;
|
|||||||
|
|
||||||
public class SalesAnnouncementData
|
public class SalesAnnouncementData
|
||||||
{
|
{
|
||||||
private final int _id;
|
private final Integer _id;
|
||||||
private final Rank[] _displayTo;
|
private final Rank[] _displayTo;
|
||||||
private final String _message;
|
private final String _message;
|
||||||
private boolean _enabled;
|
private boolean _enabled;
|
||||||
|
|
||||||
public SalesAnnouncementData(int id, Rank[] displayTo, String message, boolean enabled)
|
public SalesAnnouncementData(Integer id, Rank[] displayTo, String message, boolean enabled)
|
||||||
{
|
{
|
||||||
_id = id;
|
_id = id;
|
||||||
_displayTo = displayTo;
|
_displayTo = displayTo;
|
||||||
@ -25,7 +25,7 @@ public class SalesAnnouncementData
|
|||||||
_enabled = enabled;
|
_enabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId()
|
public Integer getId()
|
||||||
{
|
{
|
||||||
return _id;
|
return _id;
|
||||||
}
|
}
|
||||||
|
@ -4,16 +4,17 @@ import mineplex.serverdata.commands.ServerCommand;
|
|||||||
|
|
||||||
public class SalesAnnouncementDeleteCommand extends ServerCommand
|
public class SalesAnnouncementDeleteCommand extends ServerCommand
|
||||||
{
|
{
|
||||||
private String _id;
|
private Integer _id;
|
||||||
private String _from;
|
private String _from;
|
||||||
|
private boolean _clans;
|
||||||
|
|
||||||
public SalesAnnouncementDeleteCommand(String id, String from)
|
public SalesAnnouncementDeleteCommand(Integer id, String from, boolean clans)
|
||||||
{
|
{
|
||||||
_id = id;
|
_id = id;
|
||||||
_from = from;
|
_from = from;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId()
|
public Integer getId()
|
||||||
{
|
{
|
||||||
return _id;
|
return _id;
|
||||||
}
|
}
|
||||||
@ -22,4 +23,9 @@ public class SalesAnnouncementDeleteCommand extends ServerCommand
|
|||||||
{
|
{
|
||||||
return _from;
|
return _from;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isClans()
|
||||||
|
{
|
||||||
|
return _clans;
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,9 +1,8 @@
|
|||||||
package mineplex.hub.modules.salesannouncements;
|
package mineplex.hub.modules.salesannouncements;
|
||||||
|
|
||||||
import mineplex.serverdata.commands.CommandCallback;
|
import mineplex.serverdata.commands.CommandCallback;
|
||||||
import mineplex.serverdata.commands.ServerCommand;
|
|
||||||
|
|
||||||
public class SalesAnnouncementDeleteHandler implements CommandCallback
|
public class SalesAnnouncementDeleteHandler implements CommandCallback<SalesAnnouncementDeleteCommand>
|
||||||
{
|
{
|
||||||
private final SalesAnnouncementManager _manager;
|
private final SalesAnnouncementManager _manager;
|
||||||
|
|
||||||
@ -13,16 +12,16 @@ public class SalesAnnouncementDeleteHandler implements CommandCallback
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(ServerCommand command)
|
public void run(SalesAnnouncementDeleteCommand command)
|
||||||
{
|
{
|
||||||
if (!(command instanceof SalesAnnouncementDeleteCommand))
|
if (_manager.getServer().equalsIgnoreCase(command.getFrom()))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_manager.getServer().equalsIgnoreCase(((SalesAnnouncementDeleteCommand) command).getFrom()))
|
if (_manager.CLANS != command.isClans())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_manager.handleRemoteDeletion(Integer.parseInt(((SalesAnnouncementDeleteCommand)command).getId()));
|
_manager.handleRemoteDeletion(command.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,14 +1,13 @@
|
|||||||
package mineplex.hub.modules.salesannouncements;
|
package mineplex.hub.modules.salesannouncements;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
|
|
||||||
import mineplex.core.Managers;
|
import mineplex.core.Managers;
|
||||||
import mineplex.core.MiniPlugin;
|
import mineplex.core.MiniPlugin;
|
||||||
import mineplex.core.account.CoreClientManager;
|
import mineplex.core.account.CoreClientManager;
|
||||||
@ -22,22 +21,23 @@ import mineplex.serverdata.commands.ServerCommandManager;
|
|||||||
public class SalesAnnouncementManager extends MiniPlugin
|
public class SalesAnnouncementManager extends MiniPlugin
|
||||||
{
|
{
|
||||||
private static final String LINE = C.cDGreenB + C.Strike + "=============================================";
|
private static final String LINE = C.cDGreenB + C.Strike + "=============================================";
|
||||||
private final List<SalesAnnouncementData> _data = Lists.newArrayList();
|
private final Map<Integer, SalesAnnouncementData> _data = new HashMap<>();
|
||||||
private final SalesAnnouncementRepository _repo;
|
private final SalesAnnouncementRepository _repo;
|
||||||
|
public final boolean CLANS = false;
|
||||||
|
|
||||||
public SalesAnnouncementManager(JavaPlugin plugin)
|
public SalesAnnouncementManager(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super("Sales", plugin);
|
super("Sales", plugin);
|
||||||
_repo = new SalesAnnouncementRepository(plugin);
|
_repo = new SalesAnnouncementRepository(plugin, CLANS);
|
||||||
_repo.loadAnnouncements(_data);
|
_repo.loadAnnouncements(_data);
|
||||||
|
|
||||||
addCommand(new SalesAnnouncementCommand(this));
|
addCommand(new SalesAnnouncementCommand(this));
|
||||||
|
|
||||||
ServerCommandManager.getInstance().registerCommandType("SalesAnnouncementUpdate", SalesAnnouncementUpdateCommand.class, new SalesAnnouncementUpdateHandler(this));
|
ServerCommandManager.getInstance().registerCommandType(SalesAnnouncementUpdateCommand.class, new SalesAnnouncementUpdateHandler(this));
|
||||||
ServerCommandManager.getInstance().registerCommandType("SalesAnnouncementDelete", SalesAnnouncementDeleteCommand.class, new SalesAnnouncementDeleteHandler(this));
|
ServerCommandManager.getInstance().registerCommandType(SalesAnnouncementDeleteCommand.class, new SalesAnnouncementDeleteHandler(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SalesAnnouncementData> getLoadedAnnouncements()
|
public Map<Integer, SalesAnnouncementData> getLoadedAnnouncements()
|
||||||
{
|
{
|
||||||
return _data;
|
return _data;
|
||||||
}
|
}
|
||||||
@ -57,8 +57,8 @@ public class SalesAnnouncementManager extends MiniPlugin
|
|||||||
_repo.createAnnouncement(displayTo, message, data ->
|
_repo.createAnnouncement(displayTo, message, data ->
|
||||||
{
|
{
|
||||||
UtilPlayer.message(creator, F.main(getName(), "Announcement successfully created!"));
|
UtilPlayer.message(creator, F.main(getName(), "Announcement successfully created!"));
|
||||||
_data.add(data);
|
_data.put(data.getId(), data);
|
||||||
new SalesAnnouncementUpdateCommand(data.getId() + "", getServer()).publish();
|
new SalesAnnouncementUpdateCommand(data.getId(), getServer(), CLANS).publish();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,9 +73,9 @@ public class SalesAnnouncementManager extends MiniPlugin
|
|||||||
UtilPlayer.message(deletor, F.main(getName(), "Successfully deleted announcement!"));
|
UtilPlayer.message(deletor, F.main(getName(), "Successfully deleted announcement!"));
|
||||||
if (!forceRemoveFromList)
|
if (!forceRemoveFromList)
|
||||||
{
|
{
|
||||||
_data.remove(data);
|
_data.remove(data.getId());
|
||||||
}
|
}
|
||||||
new SalesAnnouncementDeleteCommand(data.getId() + "", getServer()).publish();
|
new SalesAnnouncementDeleteCommand(data.getId(), getServer(), CLANS).publish();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,23 +85,26 @@ public class SalesAnnouncementManager extends MiniPlugin
|
|||||||
_repo.updateAnnouncementStatus(data, () ->
|
_repo.updateAnnouncementStatus(data, () ->
|
||||||
{
|
{
|
||||||
UtilPlayer.message(toggler, F.main(getName(), "Successfully toggled announcement!"));
|
UtilPlayer.message(toggler, F.main(getName(), "Successfully toggled announcement!"));
|
||||||
new SalesAnnouncementUpdateCommand(data.getId() + "", getServer()).publish();
|
new SalesAnnouncementUpdateCommand(data.getId(), getServer(), CLANS).publish();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleRemoteDeletion(int id)
|
public void handleRemoteDeletion(int id)
|
||||||
{
|
{
|
||||||
_data.removeIf(data -> data.getId() == id);
|
runSync(() ->
|
||||||
|
{
|
||||||
|
_data.remove(Integer.valueOf(id));
|
||||||
UtilServer.CallEvent(new SalesAnnouncementRemoteListUpdateEvent());
|
UtilServer.CallEvent(new SalesAnnouncementRemoteListUpdateEvent());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleRemoteUpdate(int id)
|
public void handleRemoteUpdate(int id)
|
||||||
{
|
{
|
||||||
if (_data.stream().filter(data -> data.getId() == id).toArray().length > 0)
|
if (_data.containsKey(Integer.valueOf(id)))
|
||||||
{
|
{
|
||||||
_repo.loadAnnouncement(id, data ->
|
_repo.loadAnnouncement(id, data ->
|
||||||
{
|
{
|
||||||
_data.stream().filter(existing -> existing.getId() == data.getId()).forEach(existing -> existing.setEnabled(data.isEnabled()));
|
_data.get(data.getId()).setEnabled(data.isEnabled());
|
||||||
UtilServer.CallEvent(new SalesAnnouncementRemoteListUpdateEvent());
|
UtilServer.CallEvent(new SalesAnnouncementRemoteListUpdateEvent());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -109,7 +112,7 @@ public class SalesAnnouncementManager extends MiniPlugin
|
|||||||
{
|
{
|
||||||
_repo.loadAnnouncement(id, data ->
|
_repo.loadAnnouncement(id, data ->
|
||||||
{
|
{
|
||||||
_data.add(data);
|
_data.put(data.getId(), data);
|
||||||
UtilServer.CallEvent(new SalesAnnouncementRemoteListUpdateEvent());
|
UtilServer.CallEvent(new SalesAnnouncementRemoteListUpdateEvent());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -118,7 +121,7 @@ public class SalesAnnouncementManager extends MiniPlugin
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onJoin(PlayerJoinEvent event)
|
public void onJoin(PlayerJoinEvent event)
|
||||||
{
|
{
|
||||||
if (_data.isEmpty() || _data.stream().filter(data -> data.isEnabled()).toArray().length == 0)
|
if (_data.isEmpty() || !_data.values().stream().filter(data -> data.isEnabled()).findAny().isPresent())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -127,7 +130,7 @@ public class SalesAnnouncementManager extends MiniPlugin
|
|||||||
|
|
||||||
runSyncLater(() ->
|
runSyncLater(() ->
|
||||||
{
|
{
|
||||||
_data.stream().filter(data -> data.isEnabled() && data.shouldDisplayTo(rank)).forEach(data ->
|
_data.values().stream().filter(data -> data.isEnabled() && data.shouldDisplayTo(rank)).forEach(data ->
|
||||||
{
|
{
|
||||||
player.sendMessage(" ");
|
player.sendMessage(" ");
|
||||||
player.sendMessage(LINE);
|
player.sendMessage(LINE);
|
||||||
|
@ -36,10 +36,11 @@ public class SalesAnnouncementPage implements Listener
|
|||||||
private void setup()
|
private void setup()
|
||||||
{
|
{
|
||||||
_buttons.clear();
|
_buttons.clear();
|
||||||
for (int i = 0; i < _manager.getLoadedAnnouncements().size(); i++)
|
int i = 0;
|
||||||
|
for (SalesAnnouncementData data : _manager.getLoadedAnnouncements().values())
|
||||||
{
|
{
|
||||||
SalesAnnouncementData data = _manager.getLoadedAnnouncements().get(i);
|
|
||||||
_buttons.put(i, new SalesAnnouncementButton(data, this));
|
_buttons.put(i, new SalesAnnouncementButton(data, this));
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
updateButtons(false);
|
updateButtons(false);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package mineplex.hub.modules.salesannouncements;
|
package mineplex.hub.modules.salesannouncements;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@ -9,7 +11,6 @@ import com.google.common.collect.Lists;
|
|||||||
|
|
||||||
import mineplex.core.common.Rank;
|
import mineplex.core.common.Rank;
|
||||||
import mineplex.core.common.util.Callback;
|
import mineplex.core.common.util.Callback;
|
||||||
import mineplex.core.database.MinecraftRepository;
|
|
||||||
import mineplex.serverdata.database.DBPool;
|
import mineplex.serverdata.database.DBPool;
|
||||||
import mineplex.serverdata.database.RepositoryBase;
|
import mineplex.serverdata.database.RepositoryBase;
|
||||||
import mineplex.serverdata.database.column.ColumnBoolean;
|
import mineplex.serverdata.database.column.ColumnBoolean;
|
||||||
@ -18,20 +19,22 @@ import mineplex.serverdata.database.column.ColumnVarChar;
|
|||||||
|
|
||||||
public class SalesAnnouncementRepository extends RepositoryBase
|
public class SalesAnnouncementRepository extends RepositoryBase
|
||||||
{
|
{
|
||||||
private static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS salesAnnouncements (id INT NOT NULL AUTO_INCREMENT, ranks VARCHAR(250), message VARCHAR(256), enabled BOOL, PRIMARY KEY (id));";
|
private static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS salesAnnouncements (id INT NOT NULL AUTO_INCREMENT, ranks VARCHAR(250), message VARCHAR(256), enabled BOOL, clans BOOL, PRIMARY KEY (id), INDEX typeIndex (clans));";
|
||||||
|
|
||||||
private static final String GET_ANNOUNCEMENTS = "SELECT * FROM salesAnnouncements;";
|
private static final String GET_ANNOUNCEMENTS = "SELECT * FROM salesAnnouncements WHERE clans=?;";
|
||||||
private static final String GET_ANNOUNCEMENT = "SELECT * FROM salesAnnouncements WHERE id=?;";
|
private static final String GET_ANNOUNCEMENT = "SELECT * FROM salesAnnouncements WHERE id=?;";
|
||||||
private static final String UPDATE_ANNOUNCEMENT_STATUS = "UPDATE salesAnnouncements SET enabled=? WHERE id=?;";
|
private static final String UPDATE_ANNOUNCEMENT_STATUS = "UPDATE salesAnnouncements SET enabled=? WHERE id=?;";
|
||||||
private static final String INSERT_ANNOUNCEMENT = "INSERT INTO salesAnnouncements (ranks, message, enabled) VALUES(?, ?, ?);";
|
private static final String INSERT_ANNOUNCEMENT = "INSERT INTO salesAnnouncements (ranks, message, enabled, clans) VALUES(?, ?, ?, ?);";
|
||||||
private static final String DELETE_ANNOUNCEMENT = "DELETE FROM salesAnnouncements WHERE id=?;";
|
private static final String DELETE_ANNOUNCEMENT = "DELETE FROM salesAnnouncements WHERE id=?;";
|
||||||
|
|
||||||
private final JavaPlugin _plugin;
|
private final JavaPlugin _plugin;
|
||||||
|
private final boolean _clans;
|
||||||
|
|
||||||
public SalesAnnouncementRepository(JavaPlugin plugin)
|
public SalesAnnouncementRepository(JavaPlugin plugin, boolean clans)
|
||||||
{
|
{
|
||||||
super(DBPool.getAccount());
|
super(DBPool.getAccount());
|
||||||
_plugin = plugin;
|
_plugin = plugin;
|
||||||
|
_clans = clans;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runAsync(Runnable runnable)
|
private void runAsync(Runnable runnable)
|
||||||
@ -44,13 +47,13 @@ public class SalesAnnouncementRepository extends RepositoryBase
|
|||||||
Bukkit.getScheduler().runTask(_plugin, runnable);
|
Bukkit.getScheduler().runTask(_plugin, runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadAnnouncements(final List<SalesAnnouncementData> announcementList)
|
public void loadAnnouncements(final Map<Integer, SalesAnnouncementData> map)
|
||||||
{
|
{
|
||||||
runAsync(() ->
|
runAsync(() ->
|
||||||
{
|
{
|
||||||
executeQuery(GET_ANNOUNCEMENTS, resultSet ->
|
executeQuery(GET_ANNOUNCEMENTS, resultSet ->
|
||||||
{
|
{
|
||||||
final List<SalesAnnouncementData> data = Lists.newArrayList();
|
final List<SalesAnnouncementData> data = new ArrayList<>();
|
||||||
while (resultSet.next())
|
while (resultSet.next())
|
||||||
{
|
{
|
||||||
int id = resultSet.getInt("id");
|
int id = resultSet.getInt("id");
|
||||||
@ -71,15 +74,15 @@ public class SalesAnnouncementRepository extends RepositoryBase
|
|||||||
String message = resultSet.getString("message");
|
String message = resultSet.getString("message");
|
||||||
boolean enabled = resultSet.getBoolean("enabled");
|
boolean enabled = resultSet.getBoolean("enabled");
|
||||||
|
|
||||||
data.add(new SalesAnnouncementData(id, displayTo, message, enabled));
|
data.add(new SalesAnnouncementData(Integer.valueOf(id), displayTo, message, enabled));
|
||||||
}
|
}
|
||||||
|
|
||||||
runSync(() ->
|
runSync(() ->
|
||||||
{
|
{
|
||||||
announcementList.clear();
|
map.clear();
|
||||||
data.forEach(sData -> announcementList.add(sData));
|
data.forEach(sData -> map.put(sData.getId(), sData));
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}, new ColumnBoolean("clans", _clans));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +112,7 @@ public class SalesAnnouncementRepository extends RepositoryBase
|
|||||||
String message = resultSet.getString("message");
|
String message = resultSet.getString("message");
|
||||||
boolean enabled = resultSet.getBoolean("enabled");
|
boolean enabled = resultSet.getBoolean("enabled");
|
||||||
|
|
||||||
final SalesAnnouncementData data = new SalesAnnouncementData(aId, displayTo, message, enabled);
|
final SalesAnnouncementData data = new SalesAnnouncementData(Integer.valueOf(aId), displayTo, message, enabled);
|
||||||
runSync(() ->
|
runSync(() ->
|
||||||
{
|
{
|
||||||
callback.run(data);
|
callback.run(data);
|
||||||
@ -139,7 +142,7 @@ public class SalesAnnouncementRepository extends RepositoryBase
|
|||||||
runSync(() -> callback.run(data));
|
runSync(() -> callback.run(data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, new ColumnVarChar("ranks", 250, rankStr), new ColumnVarChar("message", 256, message), new ColumnBoolean("enabled", true));
|
}, new ColumnVarChar("ranks", 250, rankStr), new ColumnVarChar("message", 256, message), new ColumnBoolean("enabled", true), new ColumnBoolean("clans", _clans));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +150,7 @@ public class SalesAnnouncementRepository extends RepositoryBase
|
|||||||
{
|
{
|
||||||
runAsync(() ->
|
runAsync(() ->
|
||||||
{
|
{
|
||||||
executeUpdate(UPDATE_ANNOUNCEMENT_STATUS, new ColumnBoolean("enabled", data.isEnabled()), new ColumnInt("id", data.getId()));
|
executeUpdate(UPDATE_ANNOUNCEMENT_STATUS, new ColumnBoolean("enabled", data.isEnabled()), new ColumnInt("id", data.getId().intValue()));
|
||||||
if (after != null)
|
if (after != null)
|
||||||
{
|
{
|
||||||
runSync(after);
|
runSync(after);
|
||||||
@ -159,7 +162,7 @@ public class SalesAnnouncementRepository extends RepositoryBase
|
|||||||
{
|
{
|
||||||
runAsync(() ->
|
runAsync(() ->
|
||||||
{
|
{
|
||||||
executeUpdate(DELETE_ANNOUNCEMENT, new ColumnInt("id", data.getId()));
|
executeUpdate(DELETE_ANNOUNCEMENT, new ColumnInt("id", data.getId().intValue()));
|
||||||
if (after != null)
|
if (after != null)
|
||||||
{
|
{
|
||||||
runSync(after);
|
runSync(after);
|
||||||
|
@ -4,16 +4,18 @@ import mineplex.serverdata.commands.ServerCommand;
|
|||||||
|
|
||||||
public class SalesAnnouncementUpdateCommand extends ServerCommand
|
public class SalesAnnouncementUpdateCommand extends ServerCommand
|
||||||
{
|
{
|
||||||
private String _id;
|
private Integer _id;
|
||||||
private String _from;
|
private String _from;
|
||||||
|
private boolean _clans;
|
||||||
|
|
||||||
public SalesAnnouncementUpdateCommand(String id, String from)
|
public SalesAnnouncementUpdateCommand(Integer id, String from, boolean clans)
|
||||||
{
|
{
|
||||||
_id = id;
|
_id = id;
|
||||||
_from = from;
|
_from = from;
|
||||||
|
_clans = clans;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId()
|
public Integer getId()
|
||||||
{
|
{
|
||||||
return _id;
|
return _id;
|
||||||
}
|
}
|
||||||
@ -22,4 +24,9 @@ public class SalesAnnouncementUpdateCommand extends ServerCommand
|
|||||||
{
|
{
|
||||||
return _from;
|
return _from;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isClans()
|
||||||
|
{
|
||||||
|
return _clans;
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,9 +1,8 @@
|
|||||||
package mineplex.hub.modules.salesannouncements;
|
package mineplex.hub.modules.salesannouncements;
|
||||||
|
|
||||||
import mineplex.serverdata.commands.CommandCallback;
|
import mineplex.serverdata.commands.CommandCallback;
|
||||||
import mineplex.serverdata.commands.ServerCommand;
|
|
||||||
|
|
||||||
public class SalesAnnouncementUpdateHandler implements CommandCallback
|
public class SalesAnnouncementUpdateHandler implements CommandCallback<SalesAnnouncementUpdateCommand>
|
||||||
{
|
{
|
||||||
private final SalesAnnouncementManager _manager;
|
private final SalesAnnouncementManager _manager;
|
||||||
|
|
||||||
@ -13,16 +12,16 @@ public class SalesAnnouncementUpdateHandler implements CommandCallback
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(ServerCommand command)
|
public void run(SalesAnnouncementUpdateCommand command)
|
||||||
{
|
{
|
||||||
if (!(command instanceof SalesAnnouncementUpdateCommand))
|
if (_manager.getServer().equalsIgnoreCase(command.getFrom()))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_manager.getServer().equalsIgnoreCase(((SalesAnnouncementUpdateCommand) command).getFrom()))
|
if (_manager.CLANS != command.isClans())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_manager.handleRemoteUpdate(Integer.parseInt(((SalesAnnouncementUpdateCommand)command).getId()));
|
_manager.handleRemoteUpdate(command.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,8 +1,6 @@
|
|||||||
package mineplex.serverdata.commands;
|
package mineplex.serverdata.commands;
|
||||||
|
|
||||||
|
|
||||||
public interface CommandCallback<T extends ServerCommand>
|
public interface CommandCallback<T extends ServerCommand>
|
||||||
{
|
{
|
||||||
|
|
||||||
void run(T command);
|
void run(T command);
|
||||||
}
|
}
|
@ -1,16 +1,14 @@
|
|||||||
package mineplex.serverdata.commands;
|
package mineplex.serverdata.commands;
|
||||||
|
|
||||||
|
|
||||||
public class CommandType
|
public class CommandType
|
||||||
{
|
{
|
||||||
|
|
||||||
private Class<? extends ServerCommand> _commandClazz;
|
private Class<? extends ServerCommand> _commandClazz;
|
||||||
public Class<? extends ServerCommand> getCommandType() { return _commandClazz; }
|
public Class<? extends ServerCommand> getCommandType() { return _commandClazz; }
|
||||||
|
|
||||||
private CommandCallback _commandCallback;
|
private CommandCallback<? extends ServerCommand> _commandCallback;
|
||||||
public CommandCallback getCallback() { return _commandCallback; }
|
public CommandCallback<? extends ServerCommand> getCallback() { return _commandCallback; }
|
||||||
|
|
||||||
public CommandType(Class<? extends ServerCommand> commandClazz, CommandCallback commandCallback)
|
public CommandType(Class<? extends ServerCommand> commandClazz, CommandCallback<? extends ServerCommand> commandCallback)
|
||||||
{
|
{
|
||||||
_commandClazz = commandClazz;
|
_commandClazz = commandClazz;
|
||||||
_commandCallback = commandCallback;
|
_commandCallback = commandCallback;
|
||||||
|
@ -9,8 +9,6 @@ import mineplex.serverdata.Utility;
|
|||||||
import mineplex.serverdata.servers.ServerManager;
|
import mineplex.serverdata.servers.ServerManager;
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.JedisPool;
|
import redis.clients.jedis.JedisPool;
|
||||||
import redis.clients.jedis.JedisPoolConfig;
|
|
||||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
|
||||||
|
|
||||||
public class ServerCommandManager
|
public class ServerCommandManager
|
||||||
{
|
{
|
||||||
@ -35,7 +33,7 @@ public class ServerCommandManager
|
|||||||
public boolean isServerInitialized() { return _localServerName != null; }
|
public boolean isServerInitialized() { return _localServerName != null; }
|
||||||
public String getServerName()
|
public String getServerName()
|
||||||
{
|
{
|
||||||
return this._localServerName;
|
return _localServerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,7 +44,7 @@ public class ServerCommandManager
|
|||||||
_writePool = Utility.generatePool(ServerManager.getMasterConnection()); // Publish to master instance
|
_writePool = Utility.generatePool(ServerManager.getMasterConnection()); // Publish to master instance
|
||||||
_readPool = Utility.generatePool(ServerManager.getSlaveConnection()); // Read from slave instance
|
_readPool = Utility.generatePool(ServerManager.getSlaveConnection()); // Read from slave instance
|
||||||
|
|
||||||
_commandTypes = new HashMap<String, CommandType>();
|
_commandTypes = new HashMap<>();
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
@ -98,6 +96,7 @@ public class ServerCommandManager
|
|||||||
* @param commandType - the type of command being received
|
* @param commandType - the type of command being received
|
||||||
* @param serializedCommand - the serialized {@link ServerCommand} data.
|
* @param serializedCommand - the serialized {@link ServerCommand} data.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
public void handleCommand(final String commandType, String serializedCommand)
|
public void handleCommand(final String commandType, String serializedCommand)
|
||||||
{
|
{
|
||||||
if (!isServerInitialized())
|
if (!isServerInitialized())
|
||||||
|
Loading…
Reference in New Issue
Block a user