-Holographic Displays API- How to remove holograms near a player - bukkit

I am making a plugin. That when a command is typed. It removes the nearest Holograms to the sender/player. Now, the things I have tried are to remove the Invisible armor stands in a radius of 10 blocks. I also tried to see if there is a method to get the nearest holograms, but I had no luck. If there is any way to point to what I need to do, that would be helpful. I am not asking for code, just for what I need to look under, say a specific class etc.
Thanks, seb.
Trying to remove armor stands:
for(Entity en : player.getNearbyEntities(10, 10, 10)) {
if(en instanceof ArmorStand) {
en.remove();
}
}
My Question: Where should I look to find a way to remove nearby Holograms to the player? If you can provide code, not needed though.

//Loop through all existing holograms registered to your plugin
for (Hologram hologram : HologramsAPI.getHolograms(plugin)) {
Location playerLoc = player.getLocation();
Location hologramLoc = hologram.getLocation();
//Check if the distance between the locations are less than 10
//and deletes the hologram if true
if (playerLoc.distance(hologramLoc) < 10) {
hologram.delete();
}
}
This Holographic Displays API has a hologram delete method.
https://github.com/filoghost/HolographicDisplays/wiki

Related

webview_flutter can't hide/change some elements

Using the webview_flutter with evaluateJavascript(), I've been able to modify the style of most elements of my website, but can't understand why some elements don't get modified.
My WebView is included, and the website to display within the WebView is https://dme.com.sg/index.php?dispatch=auth.login_form
I've included a snapshot as well, showing how I can hide and modify the colours for most of the elements, yet it seems all those that are within the "form" cannot be changed.
Would appreciate any help on how I can modify those as well, especially to change their colours to a darker theme to match the colours of the app.
WebView(
initialUrl: 'https://dme.com.sg/index.php?dispatch=auth.login_form',
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (controller) {
_controller = controller;
},
onPageStarted: (url) {
_controller.evaluateJavascript(
"document.getElementsByClassName('tygh-top-panel clearfix')[0].style.display='none';"
"document.getElementsByClassName('tygh-header clearfix')[0].style.display='none';"
"document.getElementsByClassName('tygh-header')[0].style.display='none';"
"document.getElementsByClassName('tygh-footer')[0].style.display='none';"
"document.getElementsByClassName('auth-information-grid')[0].style.display='none';"
"document.getElementsByClassName('ty-breadcrumbs clearfix')[0].style.display = 'none';"
"document.getElementsByClassName('container-fluid content-grid')[0].style.background = 'black';"
"document.getElementsByClassName('ty-mainbox-title')[0].style.color = 'pink';"
"document.getElementsByClassName('buttons-container clearfix')[0].style.display = 'none';"
);
},
),
Have kept tinkering around with it, and looking up JavaScript tutorial, and I managed to find a solution. So I'm not sure HOW or WHY, so still hoping someone could comment a response that explains so I can better understand.
Something else I've learnt, it's easier to just use the "console" tab of chrome to test the java scripts on the page before moving it into flutter webview.
Using the "document.getElementsByClassName("buttons-container clearfix")" command, I got a list of where the class was being used, and found the one I wanted to change was 1. It helps that when as you type the right index number, it gets highlighted on the website.
So then using "document.getElementsByClassName("buttons-container clearfix")1.style.background = 'black'" I managed to change the style of the element I wanted.
I've included a screengrab of the chrome console here if it can help anyone else.

Algorithm Help for Directed Graph List

I have an assignment for my class where we are attempting to find the best (cheapest) path to a destination. The description is as follows:
Each tech has a name, a cost to buy that tech, a boolean saying whether or not the player has the tech already, and a list of 0 to N techs that are available for purchase when the player buys this tech. There are three categories of tech in Tactigo: Social, Military, and Science. Each of the three starts with a basic tech that the player must purchase before purchasing more advanced techs. These basic techs are special because they are always available for purchase.
Looking at the diagram, you will note that a few techs are unlocked by multiple techs. Remember that techs are unlocked as soon as ANY tech unlocks them. In other words, you need either "Being Nice to Animals" OR "Being a Dick to People" in order to buy "Attack Animal Training". You don't need both, just one. Your task is to find the cheapest way to get any given technology. The player might own any set of techs already, so you must account for that. For example, if the player already owns "Being Nice to People" and wants to find the cheapest way to get "Making Friends", the path returned should just be "Making Friends". They don't need to purchase anything else.
The Graph looks as follows:
I originally thought of doing a depth-first-search on each of the 3 categories while calculating the cost of each path taken. My Code for this function is as follows:
//---------------------------------------------------------------------------------------------------------------------
// This function finds the best path to the tech we want.
// * goalTech: The index of the tech we're looking for. Call GetTechByIndex() to get the actual Tech instance.
// * bestPath: The best path to the goal tech. This is an array sorted in the order of the best path from the
// start to the goal. This is an output variable; it's what you need to populate with this function.
//---------------------------------------------------------------------------------------------------------------------
void TechTree::FindBestPath(int goalTech, Path& bestPath)
{
//First ensure that best path is cleared out
bestPath.clear();
//Get Tech Instance for this Goal Tech
const Tech* pGoalTech = GetTechByIndex(goalTech);
//make sure we get a valid tech
assert(pGoalTech != nullptr);
//Check first if user already has this unlocked.
if (pGoalTech->HasTech())
{
//just return
return;
}
//Check if the goal tech is one of the three starting techs.
if (pGoalTech == GetBasicSocialTech()|| pGoalTech == GetBasicScienceTech() || pGoalTech == GetBasicMilitaryTech())
{
//now we know that one of the basic techs are the goal, so we just add one of those to the path
if (pGoalTech == GetBasicSocialTech())
bestPath.push_back(GetBasicSocialTech());
else if (pGoalTech == GetBasicMilitaryTech())
bestPath.push_back(GetBasicMilitaryTech());
else
bestPath.push_back(GetBasicScienceTech());
return; //now return
}
//my process will be as follows.
//1. Since all the edges are directed we need to traverse down three different graphs: Social (starting at index 0), Military (starting at index 4) and Science (starting at index 8)
//2. I am going to perform a depth-first search starting at Social and then moving down to Military and then Science.
//3. As I am performing a depth-first I am going to keep track of a path and its respective cost, if a search gets to the goal I will make sure to register that and then move onto the next graph.
//4. When there are no more paths to search I send the lowest cost one back.
///start with social at index 0
const Tech* pStartSocialTech = GetBasicSocialTech();
std::pair<int, std::vector<const Tech*>> bestCurrentPath;
//get starting cost for this category before we move into neighbors,
// if player already has this tech we set this to zero if not we get the cost of buying into this category
int startingCost = pStartSocialTech->HasTech() ? 0 : pStartSocialTech->GetCost();
/*pStartSocialNeighbors = get all neighbors for starting point at social
while (destination is not found AND there are more neighbors to pStartSocialNeighbors)
{
DFS(neighbor, dest) //if this finds the destination we store a path and its cost, otherwise it doesnt do anything and we move on to next basic tree
}
//do the same thing for military and science...
*/
}
I have a lot of comments on it but I am just wondering if this is the best route to take. Other options are Dijkstras or A* but I don't know how you would traverse the path of this directed graph. I am not looking for a direct answer since this is a homework assignment but I am looking for some guidance.
Thanks!
Going from the target to source using Dijkstras, you need to modify the stop condition if you want to stop before searching all paths. I don't see any heuristic for A* in this case.
Adding a node with a path to all known techs
You can now use Dijkstras / Bellman-Ford.
Using A* has the problem you need to find a heuristic that works. You could use depth times min cost of all edges. that requires you to already have traversed the graph to assign depth.

calculating distance between vehicles and setting speed so the distances remain the same e.g 5 meters

I am using veins 5.0 and i am trying to calculate the distance between the vehicles and setting their speed. I want to calculate it every second and i want to do it by sending wsm messages.My goal is to have for example 5 vehicles, each vehicle will communicate with the front vehicle and get its position with the intention of calculating their distance and keep it static. I am new to this and i don't know how to approach it.
I tried to do something like this on handlePositionUpdate
void TraCIDemo11p::handlePositionUpdate(cObject* obj)
{
DemoBaseApplLayer::handlePositionUpdate(obj);
// stopped for for at least 10s?
if (x<simTime()){
TraCIDemo11pMessage* wsm1 = new TraCIDemo11pMessage();
populateWSM(wsm1);
wsm1->setPosition(mobility->getPositionAt(simTime()));
wsm1->setSpeed(mobility->getSpeed());
if (dataOnSch) {
startService(Channel::sch2, 42, "Traffic Information Service");
message to self to send later
scheduleAt(computeAsynchronousSendingTime(1,ChannelType::service), wsm1);
}
else {
sendDown(wsm1);
}
}
You are describing what is, effectively, a platooning application. You might want to base your source code on Plexe, the platooning extension to Veins. It already comes with state-of-the-art distance controllers like PATH or Ploeg. More information can be found on http://plexe.car2x.org/

Detecting orientation of iPhone using C++

Embarcadero C++Builder 10.3.2 Enterprise
Searching the internet, I could not find any FMX code for this. Based on Delphi code, this should have worked but the compiler does not like it
if (Application->FormFactor->Orientations == Fmx::Types::TScreenOrientations::Landscape) {
//Landscape
}
Also, the value of Application->FormFactor->Orientations is the same whatever the orientation of the iphone. {System::SetBase = {Data = {[0] = 11 '\v'}}}
How does one determine the orientation?
The Orientations property is a TFormOrientations, which is a System::Set of TFormOrientation values. You can't use Set::operator== to compare it to a single value, which is why you are getting a compiler error. However, you can use the Set::Contains() method to check if it has a given value, eg:
if (Application->FormFactor->Orientations.Contains(Fmx::Forms::TFormOrientation::Landscape)) {
//...
}
In any case, the Orientations property specifies which orientation(s) the application's Forms are allowed to take (a value of 11 has its 1st, 2nd, and 4th bits set to 1, which correspond to the Portrait, Landscape, and InvertedLandscape orientations being enabled). It does not report what the device's current orientation is. For that, use the IFMXScreenService::GetScreenOrientation() method instead, eg:
_di_IFMXScreenService ScreenService;
if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXScreenService), &ScreenService)) {
if (ScreenService->GetScreenOrientation() == Fmx::Types::TScreenOrientation::Landscape) {
//...
}
}

Google Maps Android API v2 getVisibleRegion() returns 0

I am using the new Google Maps Android API v2 and need to detect latlng coordinates for the corners of my screen view. I use mMap.getProjection().getVisibleRegion() to do this, which works fine the first time I load the program, but if I leave the program and then re-open it (either via the back button or the home button) getVisibleRegion() returns latlng coordinates that are all (0.0, 0.0). I have a workaround where I save the VisibleRegion object as a global in the application class when I first open the program, but this seems like a bad idea. Anyone understand why the latlng coordinates go to zero (but not null) when re-opening? Thanks!
Edit: sometimes initial load gives a (0.0, 0.0) Visible Region so my workaround is not viable. Using getProjection().fromScreenLocation(point) also returns 0.
Okay, I think I solved it: I was guessing right: The map was not visible and therefore there is also no visibleRegion (in other words a region from 0,0,0,0 to 0,0,0,0). Similar to this question
Android Google Maps API v2 calling getProjection from onResume
I attached an onCameraChanged-Listener to my map. Everytime the map is moved (or the camera is available => There is a visibleRegion) this method is called.
private void initMap() {
mMap = getMap();
if (mMap != null) {
try {
mMap.setLocationSource(this);
mMap.setOnMarkerClickListener(this);
mMap.setOnCameraChangeListener(new OnCameraChangedListener() {
#Override
public void onCameraChange(CameraPosition cameraPosition) {
Log.d(TAG, "onCameraChange");
updateMapItems();
}
}
MapsInitializer.initialize(getActivity());
...
}
}
}
This listener makes sure that you have a visibleRegion.
UPDATE: Since the new update of the Google Maps API v2, there is a callback onMapReady(). I did not use it yet, but it seems to serve exactly the purpose of this question: https://developer.android.com/reference/com/google/android/gms/maps/OnMapReadyCallback.html